package com.danco.training.zaneuskaya.repository.impl;

import java.util.List;




import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.danco.training.zaneuskaya.domain.Country;
import com.danco.training.zaneuskaya.repository.CountryDao;
/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Repository
public class CountryDaoImpl extends AbstractHibernateDao<Country, Integer> implements CountryDao{

	private static final String COUNTRY_NAME = "countryName";

	@Override
	public Country read(Integer PK) throws HibernateException {
		return super.read(Country.class, PK);
	}

	@Override
	public List<Country> readAll() throws HibernateException {
		return super.readAll(Country.class, COUNTRY_NAME);
	}



	@Override
	public Country findCountryByName(String name) throws HibernateException{
		Criteria criteria = getSession().createCriteria(Country.class);
		criteria.add(Restrictions.eq(COUNTRY_NAME, name));
		return (Country) criteria.uniqueResult();
		
	}

	

}
